package net.xdclass.xdclass_shiro.service;

import net.xdclass.xdclass_shiro.dao.RoleMapper;
import net.xdclass.xdclass_shiro.dao.UserMapper;
import net.xdclass.xdclass_shiro.domain.Role;
import net.xdclass.xdclass_shiro.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhangsj
 * @date 2020/5/2 10:30
 */
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findAllUserInfoByUsername(String username) {
        User user = userMapper.findByUsername(username);
        List<Role> roles = roleMapper.findListByUserId(user.getId());
        user.setRoleList(roles);
        return user;
    }

    @Override
    public User findSimpleUserInfoById(long userId) {
        return userMapper.findById(userId);
    }

    @Override
    public User findSimpleUserInfoByUsername(String username) {
        return userMapper.findByUsername(username);
    }
}
